<template>
  <div class="login">
    <div class="login-top">
      <div class="login-title">后台管理系统</div>
      <el-form
        :model="param"
        :rules="rules"
        ref="login"
        label-width="0px"
        class="login-content"
      >
        <el-form-item prop="username">
          <el-input v-model="param.username" placeholder="username">
            <template #prepend>
              <el-button icon="el-icon-user"></el-button>
            </template>
          </el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input
            type="password"
            placeholder="password"
            v-model="param.password"
            @keyup.enter="submitForm()"
          >
            <template #prepend>
              <el-button icon="el-icon-lock"></el-button>
            </template>
          </el-input>
        </el-form-item>
        <div class="login-btn">
          <el-button type="primary" @click="submitForm()">登录</el-button>
        </div>
        <p class="login-tips">用户名和密码随便填。</p>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      //////创建两个空用户名和密码
      param: {
        username: "",
        password: "",
      },
      ////判断是否和上面填写的用户名和密码不能为空，然后进行登录
      rules: {
          username: [
              { required: true, message: "请输入用户名", trigger: "blur" }////blur失去焦点进行验证判断
          ],
          password: [
              { required: true, message: "请输入密码", trigger: "blur" }
          ]
      }
    };
  },
  created() {
      this.$store.commit("clearTags");
  },
  methods: {
    submitForm() {
      this.$refs.login.validate(e => {////validate对填写的字段自行验证，判断是否一致然后进行登录
          if (e) {
              localStorage.setItem("username", this.param.username);
              this.$message.success("登录成功");
              
              this.$router.push("/course");
          } else {
              this.$message.error("请输入账号和密码");
              return false;
          }
      });
    },
  },
};
</script>

<style scoped>
.login {
  position: relative;
  width: 100%;
  height: 100%;
  background-image: url(../assets/img/admin.jpg);
  background-size: 100%;
}
.login-title {
  width: 100%;
  line-height: 50px;
  text-align: center;
  font-size: 20px;
  color: #222;
  border-bottom: 1px solid #ddd;
}
.login-top {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 350px;
  margin: -190px 0 0 -175px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.5);
  overflow: hidden;
}
.login-content {
  padding: 30px 30px;
}
.login-btn {
  text-align: center;
}
.login-btn button {
  width: 100%;
  height: 36px;
  margin-bottom: 10px;
}
.login-tips {
  font-size: 12px;
  line-height: 30px;
  color: #fff;
}
</style>